#include "mytask.h"
#include "Alarm_Task.h"
#include "Led_Task.h"
#include "ModbusSlave_Task.h"
#include "Power_Task.h"
#include "Sensor_Read_Task.h"
#include "Time_Polling_Task.h"
#include "bsp.h"

#include "modbus.h"
#include "userconfig.h"
__align(8) static OS_STK Time_Polling_STK[TASK_STK_SIZE_L];
__align(8) static OS_STK Sensor_Read_STK[TASK_STK_SIZE_M];
__align(8) static OS_STK Led_STK[TASK_STK_SIZE_S];
__align(8) static OS_STK Power_STK[TASK_STK_SIZE_M];
__align(8) static OS_STK Alarm_STK[TASK_STK_SIZE_M];
__align(8) static OS_STK ModbusSlave_STK[TASK_STK_SIZE_M];

void Event_Create(void) {
}

void Task_Create(void) {
    INT8U os_err;
    OSTaskCreateExt(Time_Polling_Task,
                    (void*) 0,
                    (OS_STK*) &Time_Polling_STK[TASK_STK_SIZE_L - 1],
                    time_polling_prio,
                    time_polling_prio,
                    (OS_STK*) &Time_Polling_STK[0],
                    TASK_STK_SIZE_L,
                    (void*) 0,

                    OS_TASK_OPT_STK_CHK | OS_TASK_OPT_STK_CLR);
    OSTaskNameSet(time_polling_prio, "time_polling", &os_err);

    OSTaskCreateExt(Sensor_Read_Task,
                    (void*) 0,
                    (OS_STK*) &Sensor_Read_STK[TASK_STK_SIZE_M - 1],
                    sensor_read_prio,
                    sensor_read_prio,
                    (OS_STK*) &Sensor_Read_STK[0],
                    TASK_STK_SIZE_M,
                    (void*) 0,

                    OS_TASK_OPT_STK_CHK | OS_TASK_OPT_STK_CLR);
    OSTaskNameSet(sensor_read_prio, "sensor_read", &os_err);

    ;

    OSTaskCreateExt(ModbusSlave_Task,
                    (void*) 0,
                    (OS_STK*) &ModbusSlave_STK[TASK_STK_SIZE_M - 1],
                    ModbusSlave_prio,
                    ModbusSlave_prio,
                    (OS_STK*) &ModbusSlave_STK[0],
                    TASK_STK_SIZE_M,
                    (void*) 0,

                    OS_TASK_OPT_STK_CHK | OS_TASK_OPT_STK_CLR);
    OSTaskNameSet(ModbusSlave_prio, "ModbusSlave", &os_err);

    OSTaskCreateExt(Led_Task,
                    (void*) 0,
                    (OS_STK*) &Led_STK[TASK_STK_SIZE_S - 1],
                    Led_prio,
                    Led_prio,
                    (OS_STK*) &Led_STK[0],
                    TASK_STK_SIZE_S,
                    (void*) 0,

                    OS_TASK_OPT_STK_CHK | OS_TASK_OPT_STK_CLR);
    OSTaskNameSet(Led_prio, "Led", &os_err);

    OSTaskCreateExt(Power_Task,
                    (void*) 0,
                    (OS_STK*) &Power_STK[TASK_STK_SIZE_M - 1],
                    Power_prio,
                    Power_prio,
                    (OS_STK*) &Power_STK[0],
                    TASK_STK_SIZE_M,
                    (void*) 0,

                    OS_TASK_OPT_STK_CHK | OS_TASK_OPT_STK_CLR);
    OSTaskNameSet(Power_prio, "Power", &os_err);

    OSTaskCreateExt(Alarm_Task,
                    (void*) 0,
                    (OS_STK*) &Alarm_STK[TASK_STK_SIZE_M - 1],
                    Alarm_prio,
                    Alarm_prio,
                    (OS_STK*) &Alarm_STK[0],
                    TASK_STK_SIZE_M,
                    (void*) 0,

                    OS_TASK_OPT_STK_CHK | OS_TASK_OPT_STK_CLR);
    OSTaskNameSet(Alarm_prio, "Alarm", &os_err);
}
